import com.baidu.aip.nlp.AipNlp;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONObject;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;

/**
 * @author zhangdi
 * @version 1.0
 * @date 2022.4.13 9:59
 */
public class demo {
    //设置APPID/AK/SK
    public static final String APP_ID = "25956211";
    public static final String API_KEY = "4KjGx7wHpE69TMIavjYTfbhM";
    public static final String SECRET_KEY = "LOMNfq00PafB7GzYXyewd6oycG5Npedt";

    public static void main(String[] args) throws IOException {
        // 初始化一个AipNlp
        AipNlp client = new AipNlp(APP_ID, API_KEY, SECRET_KEY);

        // 可选：设置网络连接参数
        client.setConnectionTimeoutInMillis(2000);
        client.setSocketTimeoutInMillis(60000);

        // 可选：设置代理服务器地址, http和socket二选一，或者均不设置
//        client.setHttpProxy("proxy_host", proxy_port);  // 设置http代理
//        client.setSocketProxy("proxy_host", proxy_port);  // 设置socket代理

        // 调用接口
        StringBuilder sb = new StringBuilder();
        FileReader fileReader = new FileReader("E:\\nlptest.txt");
        BufferedReader br = new BufferedReader(fileReader);
        String s = null;
        while (true) {
            s = br.readLine();
            if(s == null) {
                break;
            }
            if(s.isEmpty()) {
                sb.append("\n");
            } else {
                sb.append(s);
            }

        }

        HashMap<String, Object> options = new HashMap<String, Object>();
        options.put("title", "dfdsf");

        JSONObject res = client.newsSummary(sb.toString(), 360, options);
        System.out.println(res.toString(2));

    }
}
